package com.example.chatty.ui.IMChat

import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.DarkMode
import androidx.compose.material.icons.rounded.LightMode
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.example.chatty.R
import com.example.chatty.ui.components.CircleShapeImage
import com.example.chatty.ui.theme.LocalChattyColors
import com.example.chatty.ui.theme.chattyColors
import kotlinx.coroutines.launch
import java.util.*


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeTopBar(drawerState: DrawerState) {

    val scope = rememberCoroutineScope()
    val chattyColors = LocalChattyColors.current

//    var isSearching by remember {
//        mutableStateOf(false)
//    }
//    var searchContent by remember {
//        mutableStateOf("")
//    }
    CenterAlignedTopAppBar(
        modifier = Modifier.statusBarsPadding(),
        navigationIcon = {
            IconButton(onClick = {
                scope.launch {
                    drawerState.open()
                }
//                if (!isSearching) {
//                    scope.launch {
//                        drawerState.open()
//                    }
//                }
            }) {
                CircleShapeImage(
                    size = 40.dp,
                    painter = painterResource(id = R.drawable.ava4)
                )
            }
        },
        title = {
            Text(text = "Chatty", color = MaterialTheme.chattyColors.textColor)

//            if (!isSearching) {
//                Text(text = "Chatty", color = MaterialTheme.chattyColors.textColor)
//            } else {
//                BasicTextField(
//                    value = searchContent,
//                    onValueChange = {
//                        searchContent = it.lowercase(Locale.getDefault())
//                        displayMessages = recentMessages.filter { result ->
//                            result.userProfile.nickname.lowercase(Locale.getDefault())
//                                .contains(searchContent)
//                        }.toMutableList()
//                    }) { innerTextField ->
//
//                    CenterRow(Modifier.fillMaxWidth()) {
//                        Box(
//                            modifier = Modifier.weight(1f),
//                            contentAlignment = Alignment.CenterStart
//                        ) {
//                            innerTextField()
//                        }
//                    }
//
//                }
//            }
        },
        actions = {
            IconButton(onClick = { chattyColors.toggleTheme() }) {
                Icon(
                    imageVector = if (chattyColors.isLight) Icons.Rounded.DarkMode else Icons.Rounded.LightMode,
                    contentDescription = null,
                    tint = MaterialTheme.colorScheme.onBackground
                )
            }
//            if (!isSearching) {
//                IconButton(onClick = {
//                    isSearching = true
//
//                }) {
//                    Icon(
//                        Icons.Rounded.Search,
//                        contentDescription = null,
//                        tint = MaterialTheme.chattyColors.iconColor
//                    )
//                }
//            } else {
//                IconButton(onClick = {
//                    isSearching = false
//                    displayMessages = recentMessages
//                    searchContent = ""
//                }) {
//                    Icon(
//                        Icons.Rounded.Close,
//                        contentDescription = null,
//                        tint = MaterialTheme.chattyColors.iconColor
//                    )
//                }
//            }
        }
    )
}









